Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[VPA] Add subresource status for vpa with e2e fix #5766

Merged
merged 1 commit into from
Jun 27, 2023

Conversation

wu0407
Copy link
Contributor

@wu0407 wu0407 commented May 17, 2023

Add status field in subresource on crd yaml and add new ClusterRole system:vpa-actor to patch /status subresource.
The metadata.generation only increase on vpa spec update.
Fix e2e test for patch and create vpa

What type of PR is this?

/kind bug
/kind failing-test
/kind api-change

What this PR does / why we need it:

Current vpa crd has empty subresource field, that leads to metadata.generation increase on vpa status update.
The controller-runtime has GenerationChangedPredicate to filter out update status event for cr, but it not work for vpa.
This PR add status field in subresource on crd yaml and add new ClusterRole system:vpa-actor to patch /status subresource.
The metadata.generation only increase on vpa spec update.

Which issue(s) this PR fixes:

Fixes #5675

Special notes for your reviewer:

Previous pull request is #5680 and be revert #5738, because of e2e test failed #5727.
This PR fixes e2e test failure.

Does this PR introduce a user-facing change?

Added the /status subresource to VPA
action required: If you're installing VPA with different means than the `hack/vpa-up.sh` script, you need to add the ClusterRole `system:vpa-status-actor` and corresponding ClusterRoleBinding yourself. Otherwise VPA will no longer be able to update the recommendations!
If you create vpa with status,  status be ignored in apiserver, so need to update status after create vpa.

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added kind/bug Categorizes issue or PR as related to a bug. kind/failing-test Categorizes issue or PR as related to a consistently or frequently failing test. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. area/vertical-pod-autoscaler size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 17, 2023
@wu0407
Copy link
Contributor Author

wu0407 commented May 17, 2023

@voelzmo @jbartosik

@k8s-triage-robot
Copy link

This PR may require API review.

If so, when the changes are ready, complete the pre-review checklist and request an API review.

Status of requested reviews is tracked in the API Review project.

Copy link
Collaborator

@jbartosik jbartosik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should mention the breaking change in the release notes.

Also a couple comments asking for some small code changes.

vertical-pod-autoscaler/e2e/v1/common.go Outdated Show resolved Hide resolved
vertical-pod-autoscaler/e2e/v1beta2/common.go Show resolved Hide resolved
Add status field in subresource on crd yaml and add new ClusterRole system:vpa-actor to patch /status subresource.
The `metadata.generation` only increase on vpa spec update.
Fix e2e test for patch and create vpa
@wu0407 wu0407 force-pushed the add-status-subresource branch from 9a0521a to 1384c8b Compare May 19, 2023 05:10
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 19, 2023
Comment on lines +363 to +368
// apiserver ignore status in vpa create, so need to update status
if !isStatusEmpty(&vpa.Status) {
if vpa.Status.Recommendation != nil {
PatchVpaRecommendation(f, vpa, vpa.Status.Recommendation)
}
}
Copy link
Contributor Author

@wu0407 wu0407 May 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A comment is needed in InstallVPA that create vpa with status need individual update status, so isStatusEmpty needs to be preserved, and the code may appear a bit redundant

@wu0407
Copy link
Contributor Author

wu0407 commented May 19, 2023

A comment is needed leave in InstallVPA that create vpa with status need individual update status, so isStatusEmpty needs to be preserved, and the code may appear a bit redundant

We should mention the breaking change in the release notes.

Also a couple comments asking for some small code changes.

A note in release notes is done

Copy link
Collaborator

@jbartosik jbartosik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

I left one small comment to make code a bit cleaner.

I think this is good to merge but:

  • Our release is overdue, I want to wait with merging until we release to avoid further delays
  • I want to check if we're good on the API change (this is a breaking API change)

So
/hold

@@ -372,6 +372,23 @@ func InstallVPA(f *framework.Framework, vpa *vpa_types.VerticalPodAutoscaler) {
vpaClientSet := getVpaClientSet(f)
_, err := vpaClientSet.AutoscalingV1().VerticalPodAutoscalers(f.Namespace.Name).Create(context.TODO(), vpa, metav1.CreateOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "unexpected error creating VPA")
// apiserver ignore status in vpa create, so need to update status
if !isStatusEmpty(&vpa.Status) {
if vpa.Status.Recommendation != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd write this as one condition:

if !isStatusEmpty(&vpa.Status) && vpa.Status.Recommendation != nil {

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Jun 14, 2023
@jbartosik
Copy link
Collaborator

Release is tracked in #5851

bytes, err := json.Marshal(patches)
if err != nil {
klog.Errorf("Cannot marshal VPA status patches %+v. Reason: %+v", patches, err)
return
}

return vpaClient.Patch(context.TODO(), vpaName, types.JSONPatchType, bytes, meta.PatchOptions{})
return vpaClient.Patch(context.TODO(), vpaName, types.JSONPatchType, bytes, meta.PatchOptions{}, "status")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a unit test we can add to cover this change?
Maybe using the fake client?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is already have test case on TestUpdateVpaIfNeeded

for _, tc := range testCases {
t.Run(tc.caseName, func(t *testing.T) {
fakeClient := vpa_fake.NewSimpleClientset(&vpa_types.VerticalPodAutoscalerList{Items: []vpa_types.VerticalPodAutoscaler{*tc.observedVpa}})
_, err := UpdateVpaStatusIfNeeded(fakeClient.AutoscalingV1().VerticalPodAutoscalers(tc.updatedVpa.Namespace),
tc.updatedVpa.Name, &tc.updatedVpa.Status, &tc.observedVpa.Status)
assert.NoError(t, err, "Unexpected error occurred.")
actions := fakeClient.Actions()
if tc.expectedUpdate {
assert.Equal(t, 1, len(actions), "Unexpected number of actions")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, makes sense.

@kwiesmueller
Copy link
Member

/lgtm
/hold

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 21, 2023
@kwiesmueller
Copy link
Member

The release is published, are we good to unhold @jbartosik ?

@jbartosik jbartosik added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Jun 27, 2023
Copy link
Collaborator

@jbartosik jbartosik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/approve
/hold cancel

Yup, I think we can merge this

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 27, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jbartosik, wu0407

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot merged commit 2aaa41d into kubernetes:master Jun 27, 2023
@kwiesmueller
Copy link
Member

The PR was reverted in #5897
I'll try to run the e2e test locally to reproduce. @wu0407 please reach out if I can help with getting this back in.
You can also reach me on the kubernetes slack (kwiesmueller).

@wu0407
Copy link
Contributor Author

wu0407 commented Jun 29, 2023

The PR was reverted in #5897 I'll try to run the e2e test locally to reproduce. @wu0407 please reach out if I can help with getting this back in. You can also reach me on the kubernetes slack (kwiesmueller).

please help me point what is the problem, because i has not enviroment to test. I get a acount on kubernetes slack. @kwiesmueller

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/vertical-pod-autoscaler cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/bug Categorizes issue or PR as related to a bug. kind/failing-test Categorizes issue or PR as related to a consistently or frequently failing test. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

vpa CRD not contain status subresource
5 participants